/**
 * Created by DevilsEyes on 2016/4/22.
 */
//studentList
define(['layer'], function (layer) {
    'use strict';

    var OriginList = [];
    var vm = avalon.define({
        $id: 'homeworkList',
        list: [],
        // page: 0,
        // limit: 20,
        getList: function () {
            $.ajax({
                url: '/api/admin/homework/list',
                success: function (data) {
                    OriginList = data.list;
                    vm.list = data.list.sort(function (a, b) {
                        return a.title > b.title;
                    });
                    console.dir(data.list);
                }
            })
        },
        removeHomework: function ($event, id) {
            var INDEX = layer.confirm('确认要删除这个课件吗?',
                function () {
                    $.ajax({
                        url: '/api/admin/homework',
                        method: 'DELETE',
                        data: {
                            _id: id
                        },
                        success: function (data) {
                            layer.close(INDEX);
                            if (data.code == 0) {
                                layer.msg('删除成功!');
                                vm.getList();
                            } else {
                                layer.msg(data.msg || '删除失败!');
                            }
                        }
                    })
                }
            );

        },
        editHomework: function ($event, id) {
            location.hash = '#!/homework/edit/' + id;
        },
        newHomework: function () {
            location.hash = '#!/homework/add';
        }
    });

    return {
        init: function () {
            vm.list = [];
            vm.getList();
            // $root.page = temp;
        }
    }
});
